package com.akaovi.chatroom.scene;

import com.akaovi.chatroom.client.Client;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import org.kordamp.ikonli.javafx.FontIcon;

/**
 * @author akaovi
 * @version 1.0
 * @description 好友信息板
 * @date 2022/12/9 17:30
 * @since 2022/12/9 17:30
 */
public class UserInfoBoard {
    static FontIcon avatar = new FontIcon("anto-user");
    static Label account = new Label();
    static Label username = new Label();
    static Button delete = new Button("删除好友");
    static Font font = new Font(18);

    static {
        avatar.setIconSize(50);
        MainScene.gridPane.add(avatar, 5, 2, 1, 2);
        account.setFont(font);
        MainScene.gridPane.add(account, 6, 2, 1, 1);
        username.setFont(font);
        MainScene.gridPane.add(username, 6, 3, 1, 1);
        MainScene.gridPane.add(delete, 7, 3, 1, 1);
        delete.setTextFill(Paint.valueOf("#ff3f3f"));
        delete.setOnAction(e -> {
            // 删除好友
            Client.ot.sendToDeleteFriend(account.getText());
            coverUserInfo();
            MainScene.showCommonIcon();
            FriendsList.removeOne(account.getText());
        });
        avatar.setVisible(false);
        account.setVisible(false);
        username.setVisible(false);
        delete.setVisible(false);
    }

    /**
     * 展示
     */
    public static void showUserInfo() {
        if (!account.isVisible() && account.getText().length() != 0) {
            avatar.setVisible(true);
            account.setVisible(true);
            username.setVisible(true);
            delete.setVisible(true);
            MainScene.coverCommonIcon();
        } else {
            MainScene.showCommonIcon();
        }
    }

    /**
     * 不展示
     */
    public static void coverUserInfo() {
        if (account.isVisible()) {
            avatar.setVisible(false);
            account.setVisible(false);
            username.setVisible(false);
            delete.setVisible(false);
        }
    }

    /**
     * 重置
     */
    public static void restart() {
        UserInfoBoard.account.setText("");
        UserInfoBoard.username.setText("");
    }
}
